//
//  EnterDetailOneTableViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/19.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "EnterDetailOneTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

@interface EnterDetailOneTableViewCell()


@property(nonatomic, retain) UIImageView *bigImage;

@property(nonatomic, retain) UIButton *locationBtn;

@property(nonatomic, retain) UIImageView *image;

@property(nonatomic, retain) UILabel *label;

@end

@implementation EnterDetailOneTableViewCell

- (void)dealloc
{
    [_location release];
    [_imageName release];
    [_bigImage release];
    [_locationBtn release];
    [_image release];
    [_label release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.bigImage = [[UIImageView alloc]init];
        [self.contentView addSubview:self.bigImage];
        [_bigImage release];
        
        self.locationBtn = [[UIButton alloc]init];
        [self.contentView addSubview:self.locationBtn];
        [_locationBtn release];
        [self.locationBtn addTarget:self action:@selector(locationAction:) forControlEvents:UIControlEventTouchUpInside];
       
        self.image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Enter_Location"]];
        [self.locationBtn addSubview:self.image];
        [_image release];
        
        self.label = [[UILabel alloc]init];
        self.label.textColor = [UIColor colorWithRed:0.149 green:0.516 blue:1.000 alpha:1.000];
        self.label.font = [UIFont systemFontOfSize:15 * kWidth];
        [self.locationBtn addSubview:self.label];
        [_label release];
      }
    return self;
}

-(void)locationAction:(UIButton *)btn
{
    [self.delegate sendONEToTravetTourDetailsViewController:self.ID];
}

-(void)setID:(NSNumber *)ID
{
    if (_ID != ID) {
        [_ID release];
        _ID = [ID retain];
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.bigImage.frame = CGRectMake(10 * kWidth, 10 * kHeight, self.frame.size.width - 20 * kWidth, 170 * kHeight);
    self.locationBtn.frame = CGRectMake(10 * kWidth, self.bigImage.frame.origin.y +  self.bigImage.frame.size.height + 15 * kHeight, 200 * kWidth, 20 * kHeight);
    self.image.frame = CGRectMake(0, 0, 20 * kWidth, 20 * kHeight);
    self.label.frame = CGRectMake(25 * kWidth, 0, self.locationBtn.frame.size.width - 20 * kWidth, 20 * kHeight);
}


-(void)setImageName:(NSString *)imageName
{
    if (_imageName != imageName) {
        [_imageName release];
        _imageName = [imageName copy];
    }
    [self.bigImage sd_setImageWithURL:[NSURL URLWithString:imageName] placeholderImage:[UIImage imageNamed:@"placeHoder"]];
}

-(void)setLocation:(NSString *)location
{
    if (_location != location) {
        [_location release];
        _location = [location copy];
    }
    self.label.text = location;
    if (self.label.text == nil) {
        self.image.image = nil;
    }
}


@end
